package com.example.redis.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class Test {

    private final static String lockId = "hello java";

    @Autowired
    Lock lock;

    @Scheduled(cron = "1 * * * * ? ")
    public void doSomethings(){
        boolean b = lock.getLock(lockId,1000*10);
        if(b){
            System.out.println("执行任务");
            lock.deleteLock(lockId);
        }else {
            System.out.println("没有抢到锁");
        }
    }
}
